import 'package:flutter/material.dart';
import 'package:hzy_project_template/assets/assets.dart';
import 'package:hzy_project_template/base_ui_config/common_state_widget.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/utils/utils.dart';

import 'common_widgets.dart';

class NormalToolTopWidget extends StatefulWidget {
  const NormalToolTopWidget({
    super.key,
    this.type = 0,
    this.tapCall,
    this.isNeedPadd = true,
  });
  final Function(int index)? tapCall;
  final bool isNeedPadd;
  final int type;
  @override
  State<StatefulWidget> createState() {
    return NormalToolTopState();
  }
}

class NormalToolTopState extends CommonStateWidget<NormalToolTopWidget> {
  List toolList = [
    {
      "name": LaunchIdConfig.collect.tr,
      "imgPath": Assets.commCollection,
    },
    {
      "name": LaunchIdConfig.save.tr,
      "imgPath": Assets.commDownload,
    },
    {
      "name": LaunchIdConfig.share.tr,
      "imgPath": Assets.commShare,
    },
  ];

  @override
  void initState() {
    super.initState();
    toolList = widget.type == 0
        ? toolList
        : [
            {
              "name": LaunchIdConfig.cancelFavorite.tr,
              "imgPath": Assets.commNoCollection,
            },
            {
              "name": LaunchIdConfig.oneClick.tr + LaunchIdConfig.save.tr,
              "imgPath": Assets.commDownload,
            },
            {
              "name": LaunchIdConfig.oneClick.tr + LaunchIdConfig.share.tr,
              "imgPath": Assets.commShare,
            }
          ];
  }

  @override
  Widget createBody({
    required BuildContext context,
    BoxConstraints? constraints,
  }) {
    Widget body = configToolSWidget();
    return body;
  }

  /// 创建工具分栏界面
  configToolSWidget() {
    Widget body = Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        ...List.generate(
          toolList.length,
          (index) => configToolsBtnWidget(
            imagePath: toolList[index]["imgPath"],
            text: toolList[index]["name"],
            index: index,
          ),
        ),
      ],
    );
    body = Padding(
      padding: const EdgeInsets.symmetric(vertical: 20),
      child: body,
    );

    body = Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        normamlTopLine(),
        body,
      ],
    );

    body = Container(
      padding: widget.isNeedPadd
          ? EdgeInsets.only(
              left: 20.w,
              right: 20.w,
              top: 15.w,
              bottom: configSafeBottomHeight(),
            )
          : EdgeInsets.zero,
      decoration: BoxDecoration(
        color: const Color.fromRGBO(
          40,
          39,
          39,
          1,
        ),
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(16.r),
        ),
      ),
      child: body,
    );
    return body;
  }

  /// 创建工具按钮界面
  configToolsBtnWidget(
      {required String imagePath, required String text, required int index}) {
    Widget body = HzyBtnWidget(
      btnLayoutType: BtnLayoutType.topImg,
      height: null,
      imageWidget: Container(
        width: 50,
        height: 50,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(50),
          color: const Color.fromRGBO(52, 50, 51, 1),
          boxShadow: [
            configThemeShadow(
              opacity: 0.1,
            )
          ],
        ),
        child: Center(
          child: Image.asset(
            imagePath,
            width: 24,
            height: 24,
          ),
        ),
      ),
      space: 8,
      text: text,
      textStyle: HzyTextStyle.fontBold(
        size: 14,
        color: const Color.fromRGBO(138, 138, 138, 1),
      ),
      tapCall: () {
        if (widget.tapCall != null) {
          widget.tapCall!(index);
        }
      },
    );
    return body;
  }
}
